#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=100;
typedef long long LL;
LL a[maxn],b[maxn],p[maxn];
int main(void)
{
  ///cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n,k;cin>>n>>k;
    for(LL i=1;i<=k;i++) a[i]=i;
    LL num=k;
    for(LL i=k+1;i<=n;i++){
        a[i]=--num;
    }
    cout<<endl;
    for(LL i=1;i<=n;i++) cout<<a[i]<<" ";
    cout<<endl;
    LL c1=0;
    for(LL i=1;i<=n;i++){
        for(LL j=i;j<=n;j++){
            if(a[i]>a[j]) c1++;
        }
    }
    for(LL i=1;i<=k;i++) p[i]=i;
    do{
        for(LL i=1;i<=n;i++){
            b[i]=p[a[i]];
        }
        LL c2=0;
        for(LL i=1;i<=n;i++){
            for(LL j=i;j<=n;j++){
                if(b[i]>b[j]) c2++;
            }
        }
        if(c2<=c1){
            for(LL i=1;i<=k;i++){
                cout<<p[i]<<" ";
            }
            cout<<endl;
            for(LL i=1;i<=n;i++){
                cout<<b[i]<<" ";
            }
            cout<<endl;
        }
    }while(next_permutation(p+1,p+1+k));
  }
return 0;
}
